package com.zyb.beidada.config;

import lombok.Data;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 十八岁讨厌编程
 * @date 2025/5/9 13:34
 * @PROJECT_NAME beidada-backend
 * @description Redisson配置类
 */


@Configuration
@ConfigurationProperties(prefix = "spring.redis")
@Data
public class RedissonConfig {

    // Redis服务器地址
    private String host;
    // Redis服务器端口号
    private int port;
    // Redis服务器密码
    private String password;
    // Redis服务器数据库索引
    private int database;
    // Redis服务器连接超时时间
    private int timeout;

    @Bean
    public RedissonClient getRedissonClient() {
        Config config = new Config();
        config.useSingleServer()
                .setAddress("redis://" + host + ":" + port)
                .setDatabase(database)
                .setPassword(password)
                .setConnectTimeout(timeout);

        return Redisson.create(config);
    }
}
